<?php
/**
 * Copyright (c) 2008, Julien PORTALIER
 * http://featherphp.googlecode.com/
 * 
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 */

/**
 * Manipulates text.
 */
class text
{
	/**
	 * Transforms a text to HTML, creating paragraphs.
	 * 
	 * @return String
	 * @param $text String
	 */
	function to_html($text)
	{
		$text = str_replace(array(CR), '', $text);
		$paragraphs = preg_split('/\n+\s*\n+/', $text, 0, PREG_SPLIT_NO_EMPTY);
		
		$html = '';
		foreach($paragraphs as $p)
		{
			$p = htmlspecialchars(trim($p));
			$html .= "<p>$p</p>\n";
		}
		return $html;
	}
	
	function strip_accents($text)
	{
		$chars = array("¥" => "Y", "µ" => "u", "À" => "A", "Á" => "A",
			"Â" => "A", "Ã" => "A", "Ä" => "A", "Å" => "A",
			"Æ" => "A", "Ç" => "C", "È" => "E", "É" => "E",
			"Ê" => "E", "Ë" => "E", "Ì" => "I", "Í" => "I",
			"Î" => "I", "Ï" => "I", "Ð" => "D", "Ñ" => "N",
			"Ò" => "O", "Ó" => "O", "Ô" => "O", "Õ" => "O",
			"Ö" => "O", "Ø" => "O", "Ù" => "U", "Ú" => "U",
			"Û" => "U", "Ü" => "U", "Ý" => "Y", "ß" => "s",
			"à" => "a", "á" => "a", "â" => "a", "ã" => "a",
			"ä" => "a", "å" => "a", "æ" => "a", "ç" => "c",
			"è" => "e", "é" => "e", "ê" => "e", "ë" => "e",
			"ì" => "i", "í" => "i", "î" => "i", "ï" => "i",
			"ð" => "o", "ñ" => "n", "ò" => "o", "ó" => "o",
			"ô" => "o", "õ" => "o", "ö" => "o", "ø" => "o",
			"ù" => "u", "ú" => "u", "û" => "u", "ü" => "u",
			"ý" => "y", "ÿ" => "y"
		);
		return strtr($text, $chars);
	}
}
?>